﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PSE.Tools.SchemaComparer.Comparer;

namespace PSE.Tools.SchemaComparer.WindowsApp
{
    /// <summary>
    /// Interaction logic for UcCompareResultView.xaml
    /// </summary>
    public partial class UcCompareResultView : UserControl
    {
        public UcCompareResultView()
        {
            InitializeComponent();
        }
        #region Visualizar Resultdo Comparação
        public MainWindow ParentWindow;

        private void btnVisualizar_Click(object sender, RoutedEventArgs e)
        {
            string file = txtCompareResultFile1.Text.Trim();

            if (string.IsNullOrEmpty(file))
            {
                MessageBox.Show("- Arquivo de Entrada deve ser informado");
            }
            else
            {
                try
                {
                    DBSchemaCompareResult result = DBSchemaComparer.LoadCompareResultFromXmlFile(file);
                    CompareResultView crView = new CompareResultView(result);
                    crView.Owner = this.ParentWindow;
                    crView.ShowDialog();
                }
                catch
                {
                    MessageBox.Show("Ocorreu um erro no carregamento do arquivo de resultado de comparação. Verifique se o arquivo informado é um arquivo válido.");
                }
            }
        }

        private void btnFileBrowse_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            dialog.Filter = "Xml File |*.xml";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtCompareResultFile1.Text = dialog.FileName;
            }
        }
        #endregion


        private void ShowLoadingPanel()
        {
            if (ParentWindow != null)
                ParentWindow.ShowLoadingPanel();
        }

        private void HideLoadingPanel()
        {
            if (ParentWindow != null)
                ParentWindow.HideLoadingPanel();
        }
    }
}
